/*
 * @Description: 配置文件
 * @Author: hai-27
 * @Date: 2020-02-07 16:23:00
 * @LastEditors: Zhang Yingying
 * @LastEditTime: 2020-12-03 23:26:49
 */

const path = require("path");
const WebpackBar = require("webpackbar");
const resolve = dir => path.join(__dirname, dir);
const HardSourceWebpackPlugin = require("hard-source-webpack-plugin");

module.exports = {
  publicPath: "./",
  devServer: {
    open: true,
    overlay: {
      warnings: false,
      errors: false
    },
    proxy: {
      "/api": {
        //"http://47.115.85.237:3000/", // 线上后端地址
        target: "http://localhost:8000",
        changeOrigin: true, //允许跨域
        pathRewrite: {
          "^/api": ""
        }
      }
    }
  },
  runtimeCompiler: true,
  productionSourceMap: false,
  css: {
    requireModuleExtension: true,
    sourceMap: true,
    loaderOptions: {
      scss: {
        /*sass-loader 9.0写法，感谢github用户 shaonialife*/
        additionalData(content, loaderContext) {
          const { resourcePath, rootContext } = loaderContext;
          const relativePath = path.relative(rootContext, resourcePath);
          if (
            relativePath.replace(/\\/g, "/") !==
            "src/assets/scss/variables.scss"
          ) {
            return '@import "src/assets/scss/variables.scss";' + content;
          }
          return content;
        }
      }
    }
  },
  configureWebpack() {
    return {
      resolve: {
        alias: {
          "@": resolve("src")
        }
      },
      plugins: [
        new HardSourceWebpackPlugin(),
        new WebpackBar({
          name: "校园电子产品购物网"
        })
      ]
    };
  }
};
